package com.vsen.lpr.service;

import com.vsen.lpr.common.exception.BusinessException;
import com.vsen.lpr.common.model.Response;
import com.vsen.lpr.common.utils.RedisUtils;
import com.vsen.lpr.pojo.dto.AddRecordToRedisDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class TimeLineService {

    @Autowired
    RedisUtils redisUtils;

    public Response<Boolean> addRecordToRedis(AddRecordToRedisDto dto){
        if(Objects.isNull(dto.getUserId())){
            throw new BusinessException("20001", "userID不能为空");
        }
        Boolean addZset =
                redisUtils.addZset(dto.getUserId().toString(), dto.getRecordItem(), System.currentTimeMillis());
        return Response.success(addZset);
    }

    public Response<Boolean> deleteRecordByKAndV(AddRecordToRedisDto dto){
        if(Objects.isNull(dto.getUserId())){
            throw new BusinessException("20001", "userID不能为空");
        }
        Long deleteZset = redisUtils.deleteZset(dto.getUserId().toString(), dto.getRecordItem());
        return Objects.equals(deleteZset, 1) ? Response.success(true) : Response.success(false);
    }



}
